/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package iteso.compiladores.logo;

import iteso.compiladores.logo.lexer.Lexer;
import iteso.compiladores.logo.node.Start;
import iteso.compiladores.logo.parser.Parser;
import java.io.PushbackReader;
import java.io.StringReader;

/**
 *
 * @author GTWAVALON
 */
public class Compiler {
    public static String Compile(String instructions) {
		String output = ""; Helper.setOutput("");
        try {
//            System.out.println("Se esta haciendo el analisis lexico y semantico =)");


            // Create a Parser instance.
            Parser p =
                    new Parser(
                    new Lexer(
                    new PushbackReader(
                    new StringReader(instructions), 1024)));


            // Parse the input.
            Start tree = p.parse();
            output += tree;


            // Apply the translation.
            tree.apply(new Translator());
            output += (Helper.getOutput().equals(" ")?"":("\n\rOutput:"+Helper.getOutput()));
        } catch (Exception e) {
			output += "\n\rError: " + instructions ;
            output += e.getMessage();
        }
		return output;
    }
}
